﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DepartmentsManager.aspx.cs" Inherits="RegisterWeb.Manager.HospitalManager.DepartmentsManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
       <link href="../../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

    <script type="text/javascript">

        var url; //提交数据的路径
        var formId; //当天要提交的Form的编号
        var dialogId; //对话框的编号

        var successCallback = function (result) {
            //result为请求处理后的返回值
            var result = eval('(' + result + ')');
            if (result.success) {
                $.messager.show({
                    title: 'Success',
                    msg: result.msg
                });
                $(dialogId).dialog('close');
                $('#dg').datagrid('reload');
            } else {
                $.messager.show({
                    title: 'Error',
                    msg: result.msg
                });
            }
        }

        $(function () {
            //预加载编辑框
            $("#editDepartmentInfo").dialog({
                "title": "编辑科室信息",
                width: 500,
                height: 450,
                href: 'EditDepartment.aspx'
            });
            $("#editDepartmentInfo").dialog('open').dialog('close');

            $('#dg').datagrid({

                onDblClickRow: function (rowIndex, rowData) {
                    $('#editDepartmentInfo').dialog('open');
                    $("#textDepartmentName").val(rowData.Name);
                    $("#textDepartmentDes").val(rowData.Introduce);
                    $("#hoistal").combobox('setValue', rowData.HosptialID);

                    //      $('#edit').form('clear');
                    url = 'ashx/DepartmentsManagerService.ashx?action=edit&id=' + rowData.ID;
                    formId = "#edit";
                    dialogId = "#editDepartmentInfo";
                }
            });

        });
        //编辑科室部分
        function editDepartmentInfo() {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#editDepartmentInfo').dialog('open');
                $("#textDepartmentName").val(row.Name);
                $("#textDepartmentDes").val(row.Introduce);
                $("#hoistal").combobox('setValue', row.HosptialID);
                //   $('#edit').form('clear');

                url = 'ashx/DepartmentsManagerService.ashx?action=edit&id=' + row.ID;
                formId = "#edit";
                dialogId = "#editDepartmentInfo";

            }
            else {
                $.messager.alert("提示", "您没有选中任何行！");
            }
        }

        //添加科室部分
        function addDepartmentInfo() {
            $("#addDepartmentInfo").dialog({
                "title": "新建科室信息",
                width: 500,
                height: 450,
                href: 'AddDepartment.aspx'
            });
            $('#addDepartmentInfo').dialog('open');
            $('#add').form('clear');

            url = 'ashx/DepartmentsManagerService.ashx?action=add';
            formId = "#add";
            dialogId = "#addDepartmentInfo";
        }
        function saveInfo() {

            $(formId).form('submit', {
                url: url,
                onSubmit: function () {
                   
                    return $(this).form('validate');
                },
                success: successCallback
            });
        }

        //  删除代码部分
        function deleteAdminUser() {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $.messager.confirm('删除提示', '确定要删除' + row.Name + '吗', function (r) {
                    if (r) {
                        $.post('ashx/DepartmentsManagerService.ashx', { id: row.ID, action: 'delete' }, function (data, status) {
                        
                            if (data == "ok") {
                                $('#dg').datagrid('reload');
                            } else {
                                $.messager.show({
                                    title: 'Error',
                                    msg: '删除该科室失败!'
                                });
                            }
                        });
                    }
                });
            }
        }

        //多条件查询方法
        function tsearch() {
            var hoistalName = $("#hoistalName").combobox("getValue");
            var depName = $("#depName").val();
          
                $('#dg').datagrid('options').pageNumber = 1;  
                $('#dg').datagrid('getPager').pagination({pageNumber: 1});
              $('#dg').datagrid('options').url = 'ashx/DepartmentsManagerService.ashx?action=search&hospName='+hoistalName+'&depName='+depName;
              $('#dg').datagrid("reload");
        }
        
    </script>


</head>
<body>
    <form id="form1">
    <div region="center" title="科室信息管理" >

    <div  class="easyui-panel" title="查询条件" style="width:850px;height:80px" collapsible="true"
    >

    <div class="searchitem">
    <label>医院名：</label>
     <select id="hoistalName" name="selectHosptial">
     </select>
       <script type="text/javascript">

           $("#hoistalName").combobox({
               url: "ashx/HospitalInfoService.ashx?action=search",
               valueField: "HosptialItemID",
               textField: "HosptialItemName",
               panelHeight: "auto"
           });

     </script>
    </div>
    <div class="searchitem">
    <label>科室名：</label>
    <input type="text" id="depName" class="easyui-validatebox" />
    </div>
    
<div class="searchitem">
<a href="#" class="easyui-linkbutton" onclick="tsearch()" >查询</a>
</div>

    </div>

<table id="dg" title="科室信息管理" class="easyui-datagrid" style="width:850px;height:550px"
			url="ashx/DepartmentsManagerService.ashx?action=list"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true"   idField='ID'
            pageSize="20"
            >
		<thead>
			<tr>
				<th field="Name" width="50">科室名</th>
				<th field="Hospital" width="50">所属单位</th>
				<th field="Introduce" width="50">科室介绍</th>
                <th field="AddTime" width="50">添加时间</th>
                <th field="Recoder" width="50">记录人</th>
                <th field="State" width="50">状态</th>
			</tr>
		</thead>
	</table>

    <div id="toolbar" style="padding:5px;height:auto">
					<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addDepartmentInfo()">添加科室</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editDepartmentInfo()">编辑科室</a>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteAdminUser()">删除科室</a>
    </div>


			<div id="addDepartmentInfo" class="easyui-dialog" closed="true" buttons="#addDepartmentInfo-buttons" style="padding:10px 20px">
        	</div>
			<div id="addDepartmentInfo-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addDepartmentInfo').dialog('close')">关闭</a>
			</div>

            <div id="editDepartmentInfo" class="easyui-dialog" closed="true" buttons="#editDepartmentInfo-buttons" style="padding:10px 20px">
        	</div>
            <div id="editDepartmentInfo-buttons">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveInfo()">保存</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#editDepartmentInfo').dialog('close')">关闭</a>
			</div>

    </div>
    </form>
</body>
</html>
